#include "CameraImpl.h"
#include "CaptureFactoryImpl.h"

GCamera* CaptureFactoryImpl::ConnectCamera(int iCamid, ProcessCallback process, EventCallback evt, void* pContext)
{
    CameraImpl* pCamera = new CameraImpl(iCamid, process, evt, pContext);
    if (pCamera->Init() == false) {
        wcscpy_s(m_LastError, pCamera->GetLastError());
        delete pCamera;
        pCamera = nullptr;
    }
    return pCamera;
}

void CaptureFactoryImpl::ReleaseCamera(GCamera*& pCam)
{
    delete pCam;
    pCam = 0;
}

CaptureFactoryImpl* theFactory = 0;
int g_Ref = 0;

extern "C" __declspec(dllexport) GCaptureFactory* CreateFactory()
{
    if (theFactory == 0) {
        theFactory = new CaptureFactoryImpl;
    }
    g_Ref++;
    return theFactory;
}

extern "C" __declspec(dllexport) void DestroyFactory(GCaptureFactory*& pFac)
{
    g_Ref--;
    if (g_Ref == 0) {
        delete theFactory;
        theFactory = 0;
    }
    pFac = 0;
}
